Cry about...
WMIC
WMIC (Windows Management Instrumentation Command-Line) is a command line tool that lets you obtain information and perform various functions on the local Windows computer or remote Windows computer.
To run WMIC simply open a command prompt (you will need to use an
elevated command prompt for some actions) and then type "wmic
":
C:\>wmic
wmic:root\cli>
You can then enter WMIC commands.
Alternatively you can enter a WMIC command directly from the command prompt by appending the command to the wmic line:
C:\>wmic printer list status
.
.
C:\>
The following is a list of WMIC commands that I have found useful, it is not comprehensive:
- diskdrive get status
- Show the SMART status of each disk drive. Anything other than "OK" indicates a problem with the drive. Be aware that drives can fail without SMART indicating a problem.
- List installed software
product get name
- Be aware that this may not return immediately.
- To look for software with a name like (say ".. Apple ..") use:
product where "name like '%Apple%'"
- List printers
- printer list status
- List running processes
process list
will list the application being run by each process (only).process list brief
shows a short list of properties.process list full
shows about everything there is to know about each running process.process list /?
will show what information is available about each process. Then to get specific bits of information:
process list get Name, Handle, Status
[, some-other
]- Run a WMIC command remotely on another computer
- Put
/node:computer
at the front of the command. For example:
/node:consult2 printer list status
will list the status of each printer on the remote computer called 'consult2'. - Send output to a file
- use /output:file-name and /format:format before the desired
command, for example:
/output:c:\temp\printers.csv printer list status /format:CSV
The message "Invalid file name." seems to indicate that WMIC lacks permission to write to that file. Common format specifiers are CSV (comma separated value) and HTABLE (HTML table). - Show cpu information
- cpu
shows basic information. To see what information is available:
cpu /?
then to retrieve that information:
cpu get name, caption, maxclockspeed [, etc] - Show operating system
os
- Terminate a process
- To terminate a known named program:
process where name="program.exe" call terminate
- Uninstall an application
product where name="product-name" call uninstall
- You will be
prompted to confirm the uninstall. To avoid the confirmation add the
flag
/nointeractive
, so: product where name="product-name" call uninstall /nointeractive
- Be aware that it there may be a pause before it confirms or uninstalls the application.
- To uninstall the same application from a list of computers:
/failfast:on /node:comp1, comp2 product where name="product-name" call uninstall /nointeractive
- The switch
/fastfail:on
means that it won't hang waiting if a machine isn't responding (i.e. not available). To read the list of computers from a file: /failfast:on /node:@list.txt product where name="product-name" call uninstall /nointeractive
About the author: Brian Cryer is a dedicated software developer and webmaster. For his day job he develops websites and desktop applications as well as providing IT services. He moonlights as a technical author and consultant.